import { ref, reactive} from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
  let userInfo = ref({})
  let token = ref("");
  let mac = ref("");

  const setUserInfo = (newValue) =>{
    userInfo.value = newValue;
  }

  const setToken = (newValue) => {
    token.value = newValue;
  }

  const setMac = (newValue) => {
    mac.value = newValue;
  }
  const clearUserInfo = () => {
    userInfo.value = {};
    token.value = "";
    // mac.value = "";
    localStorage.removeItem('user')
  };
    
  return { userInfo, token, mac, setUserInfo, setToken, setMac, clearUserInfo }
}, {
  persist: true //持久化存储(为了刷新页面，存储值不消失)
})
